package de.htw_saar.mad_ea;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

//import android.support.v4.app.NavUtils;

public class MainActivity extends Activity {
	CalculatorOps calc;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		// getActionBar().setDisplayHomeAsUpEnabled(true);
		calc = CalculatorOps.getInstance(this);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.menu_settings:
			Intent additionals = new Intent(this, AdditionalOperations.class);
			MainActivity.this.startActivity(additionals);
		}
		return super.onOptionsItemSelected(item);
	}
	
	public void actions (View v) {
		switch(v.getId()){
		case R.id.button_0:
		case R.id.button_1:
		case R.id.button_2:
		case R.id.button_3:
		case R.id.button_4:
		case R.id.button_5:
		case R.id.button_6:
		case R.id.button_7:
		case R.id.button_8:
		case R.id.button_9:
		case R.id.button_bracket_open:
		case R.id.button_bracket_close:
		case R.id.button_sep:
			calc.write_number(v);
			break;
		case R.id.button_c:
			calc.clear(v);
			break;
		case R.id.button_del:
			calc.delete(v);
			break;
		case R.id.button_div:
		case R.id.button_mul:
		case R.id.button_add:
		case R.id.button_sub:
			calc.write_operator(v);
			break;
		case R.id.button_sol:
			calc.solution(v);
			break;
		}
	}
}
